package com.global.emc.spring.exception.handler.emcexception;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.global.emc.core.exception.IEMCException;
import com.global.emc.core.exception.impl.TokenValidationEMCException;

/**   
 *  
 * @Description:  [处理Token类型异常]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年2月21日 下午4:01:16]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年2月21日 下午4:01:16]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
public class TokenValidationEMCExceptionHandler extends ValidationEMCExceptionHandler {
	private String defaultErrorView;
	private String queryStateUrl="_queryStateUrl";
	private Map<String,String> exceptionCodeMappings;

	public String getDefaultErrorView() {
		return defaultErrorView;
	}
	public void setDefaultErrorView(String defaultErrorView) {
		this.defaultErrorView = defaultErrorView;
	}
	public String getQueryStateUrl() {
		return queryStateUrl;
	}
	public void setQueryStateUrl(String queryStateUrl) {
		this.queryStateUrl = queryStateUrl;
	}
	public Map<String, String> getExceptionCodeMappings() {
		return exceptionCodeMappings;
	}
	public void setExceptionCodeMappings(Map<String, String> exceptionCodeMappings) {
		this.exceptionCodeMappings = exceptionCodeMappings;
	}

	@Override
	public boolean supports(IEMCException emcException) {
		return emcException instanceof TokenValidationEMCException;
	}

	@Override
	public void handlerException(HttpServletRequest request, HttpServletResponse response, Object handlerMethod, IEMCException emcException, ModelAndView modelAndView) {
		modelAndView.setViewName(defaultErrorView);
		modelAndView.addObject(queryStateUrl, exceptionCodeMappings.get(emcException.getMessage()));
	}

}
